package com.study.services;

import java.math.BigDecimal;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.study.model.jdao.IOrderformDAO;
import com.study.model.jdao.IScheduleformDAO;
import com.study.model.mdao.InstMapper;
import com.study.model.mdao.OrderFormDetailMapper;
import com.study.model.mdao.ScheduleFormMapper;
import com.study.model.pojo.Orderform;
import com.study.model.pojo.Scheduleform;

@Service
@Transactional(rollbackOn = Exception.class)
public class ScheduleFormService {
	@Autowired
	ScheduleFormMapper mapper;
	@Autowired
	IOrderformDAO dao;
	@Autowired
	IScheduleformDAO sDao;
	@Autowired
	OrderFormDetailMapper omapper;
	
	
	/**
	 * 采购单关联订单
	 * @return
	 */
	public List<JSONObject> queryLinkOrder() {
		return omapper.queryOidNone();
	}
	
	
	public Orderform selectByOid(int oId) {
		return dao.findByOId(oId);
	}
	
	/**
	 * 新增采购单
	 * @param scheduleform
	 */
	public void insert(Scheduleform scheduleform) {
		sDao.save(scheduleform);
	}
	
	
	/**
	 * 带条件的查询
	 * 
	 * @param pageNum
	 * @param pageNum
	 * @param input
	 * @param selects
	 * @return
	 */

	public List<JSONObject> selectBySel(int pageNum, int pageSize, String supname,String theme, String selects,Integer use_id) {
		String schstates = null;
		PageHelper.startPage(pageNum, pageSize);
		if (selects.length()>0) {
			schstates = selects;
		} 
		return mapper.selectByWhere(supname, theme, schstates, use_id);
	}
	
	/**
	 * 根据id查询
	 * @param goo_id
	 * @return
	 */
	public JSONObject findById(String schno) {
		return mapper.findBySchno(schno);
	}
	
	public JSONObject sele(Integer schno) {
		return mapper.findById(schno);
	}
	
	/**
	 * 付款
	 * @param schno
	 */
	public void updatepay(Integer schno,BigDecimal payed) {
		mapper.updatepay(schno,payed);
	}
	
	/**
	 * 生成入库单
	 * @param schno
	 */

	public void selectById(Integer schno) {
		mapper.updatestate(schno);
	}
	
	/**
	 * 删除一条数据
	 * @param id
	 */
	public void delete(Integer id) {
		 mapper.detele(id);
	}

}
